<%@page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@include file="/wx/page/session.jsp"%>
<c:set var="userId" value="${param.userId}" />
<c:set var="deptId" value="${param.deptId}" />
<c:set var="deptCode" value="${param.deptCode}" />
<c:set var="deptParentId" value="${param.deptParentId}" />
<c:set var="taskId" value="${param.taskId}" />
<c:set var="moneyId" value="${param.moneyId}" />
<c:set var="moneyType" value="${param.moneyType}" />
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no, width=device-width">
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="black" name="apple-mobile-web-app-status-bar-style">
    <title>收支管理</title>
    <link rel="stylesheet" href="${ctx}/wx/css/default.css"/>
    <link rel="stylesheet" href="${ctx}/wx/css/picker.css"/>
    <script type="text/javascript" src="${ctx}/wx/js/picker.min.js"></script>
    <script type="text/javascript" src="${ctx}/wx/js/picker.data.js"></script>
    <script type="text/javascript" src="${ctx}/dwr/engine.js"></script>
    <script type="text/javascript" src="${ctx}/dwr/util.js"></script>
    <script type="text/javascript" src="${ctx}/dwr/interface/MoneyService.js"></script>
    <script type="text/javascript" src="${ctx}/wx/js/alert.js"></script>
</head>
<body style="text-align: center;">
<form id="moneyForm" name="moneyForm" method="post">
    <fieldset class="contact-inner">
        <input type="hidden" id="deptId" name="deptId" value="${deptId}">
        <input type="hidden" id="taskId" name="taskId" value="${taskId}">
        <input type="hidden" id="moneyId" name="moneyId" value="${moneyId}">
        <input type="hidden" id="moneyInOut" name="moneyInOut" value="" required>
        <input type="hidden" id="moneyState" name="moneyState" value="1">
        <p class="contact-input">
            <select id="moneyType" name="moneyType" onchange="setMoneyInOut()" required>
                <option value="">费用类型</option>
                <%--<option value="1">信息费</option>--%>
                <option value="2">销售款</option>
                <option value="3">采购款</option>
            </select>
        </p>
        <p class="contact-input">
            <input type="tel" id="moneyAmount" name="moneyAmount" placeholder="必填 金额" required>
        </p>
        <p class="contact-input">
            <input type="search" id="moneyRemark" name="moneyRemark" placeholder="备注">
        </p>
        <p class="contact-submit">
            <input type="button" value="保存" onclick="submitMoney()">
        </p>
    </fieldset>
</form>
</body>
</html>
<script type="text/javascript">
    if("${moneyId}" > 0) {
        var money = new Money();
        money.deptId = "${deptId}";
        money.taskId = "${taskId}";
        money.moneyId = "${moneyId}";
        MoneyService.selectMoneyList(money, callbackSelectMoneyList);
    }
    function callbackSelectMoneyList(list) {
        var money = list[0];
        dwr.util.setValues(money);
    }
    function setMoneyInOut() {
        var moneyType = dwr.util.getValue("moneyType");
        if(moneyType == 1 || moneyType == 2) {
            dwr.util.setValue("moneyInOut", 1);
        } else if(moneyType == 3) {
            dwr.util.setValue("moneyInOut", -1);
        }
    }
    function submitMoney() {
        if (validate($("moneyForm"))) {
            if("${moneyId}".length > 0) {
                updateMoney();
            } else {
                insertMoney();
            }
        }
    }
    function insertMoney() {
        var money = dwr.util.getFormValues("moneyForm");
        MoneyService.insertMoney(money, callback);
    }
    function updateMoney() {
        var money = dwr.util.getFormValues("moneyForm");
        MoneyService.updateMoney(money, callback);
    }
    function callback() {
        location = "${ctx}/wx/page/money_list.jsp?userId=${userId}&deptId=${deptId}&deptCode=${deptCode}&deptParentId=${deptParentId}&taskId=${taskId}";
    }
</script>